package com.app.common.db.sqlite;

import android.content.Context;

import net.sqlcipher.DatabaseErrorHandler;
import net.sqlcipher.database.SQLiteDatabase;
import net.sqlcipher.database.SQLiteDatabaseHook;
import net.sqlcipher.database.SQLiteOpenHelper;

/**
 * Created by zhoulikai on 17/2/27.
 */

public abstract class BaseCipDBHelper extends SQLiteOpenHelper {

    public BaseCipDBHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version, SQLiteDatabaseHook hook) {
        super(context, name, factory, version, hook);
        init(context);
    }

    public BaseCipDBHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version, SQLiteDatabaseHook hook, DatabaseErrorHandler errorHandler) {
        super(context, name, factory, version, hook, errorHandler);
        init(context);
    }

    public BaseCipDBHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
        init(context);
    }

    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        createTable(sqLiteDatabase);
    }

    public abstract void createTable(SQLiteDatabase db);

    private void init(Context context) {
        loadLibs(context);
    }

    private void loadLibs(Context context) {
        if (context == null) {
            return;
        }
        SQLiteDatabase.loadLibs(context);
    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {

    }
}
